<template>
	<view class="home">
		<!-- {{msg}} -->
		<uni-search-bar @confirm="doSearch" v-model="key" />

		<swiper style="height: 200px;" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000"
			circular="true" indicator-color="#fff" indicator-active-color="#f00">
			<swiper-item v-for="(item,index) in bannerGoodsList" :key="index">
				<view class="swiper-item">
					<image :src="item.goods_big_logo" style="width: 100%;" mode="widthFix"></image>
				</view>
			</swiper-item>
		</swiper>
		<!-- 商品分类 -->
		<view class="cateList">
			<view class="item" v-for="(item,index) in cateOneLst" :key="index">
				<view class="logo">
					<image :src="item.icon" mode=""></image>
				</view>
				<view class="name">{{item.name}}</view>
			</view>
		</view>

		<!-- 精选商品列表 -->
		<view class="title">
			精选商品
		</view>
		<view class="selectList">
			<view class="item" v-for="(item,index) in selectedLst" :key="index">
				<view class="pic">
					<image :src="item.goods_big_logo" mode=""></image>
				</view>
				<view class="name">
					{{item.name}}
				</view>
				<view class="msg">
					<view class="price">
						{{item.price}}
					</view>
					<view class="tag">
						精选
					</view>

				</view>
			</view>
		</view>


	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		onLoad
	} from "@dcloudio/uni-app"
	let bannerGoodsList = ref([])
	let key = ref("")

	onLoad(() => {
		getBanner()
		getCateOneLst()
		getSelectedLst()
	})

	function doSearch() {
		uni.showToast({
			title: key.value
		})
	}

	async function getBanner() {
		let res = await uni.$post("/goodsPromoteSelect", {
			"is_selected": 1,
			"is_promote": 0,
			"page": 1,
			"number": 5,
		})

		if (res.code == 200) {
			bannerGoodsList.value = res.goodsList.map(item => {
				item.goods_big_logo = uni.$base_url + item.goods_big_logo
				return item
			})
		}
		// console.log(bannerGoodsList.value)

	}


	const cateOneLst = ref([])
	async function getCateOneLst() {
		let res = await uni.$post("/categoryListLevel", {
			"level": 0
		})
		if (res.code == 200) {
			cateOneLst.value = res.result.map(item => {
				item.icon = uni.$base_url + item.icon
				return item
			})
		}
		// console.log(cateOneLst.value)
	}


	const selectedLst = ref([])
	async function getSelectedLst() {
		let res = await uni.$post("/goodsPromoteSelect", {
			"is_selected": 1,
			"is_promote": 0,
			"page": 1,
			"number": 20,
		})
		if (res.code == 200) {
			selectedLst.value = res.goodsList.map(item => {
				item.goods_big_logo = uni.$base_url + item.goods_big_logo
				return item
			})
		}
		// console.log(selectedLst.value)
	}

	// uni.request({
	// 	url:"https://unidemo.dcloud.net.cn/api/news",
	// 	success: (res) =>{F
	// 		console.log(res)
	// 	}
	// })

	// const request = function(url,method,data)
	// {
	// 	return new Promise((resolve,reject) =>{
	// 		uni.request({
	// 			url:,
	// 			method,
	// 			data,
	// 			success: (res) {
	// 				resolve(res)
	// 			},
	// 			fail: (err) =>{
	// 				reject(err)
	// 			}
	// 		})
	// 	})
	// }

	// async function getNews(){
	// 	let lst = await request("https://unidemo.dcloud.net.cn/api/news")
	// 	console.log(lst);
	// }
	// let msg=ref({})
	// async  function getnews()
	// {
	// 	let lst = await uni.$get("https://unidemo.dcloud.net.cn/api/news")
	// 	console.log(lst)
	// 	msg.value=lst
	// }
	// getnews()
</script>

<style>
	/* 商品列表 */
	.cateList {
		display: flex;
		justify-content: space-around;
		margin-top: 20rpx;
	}

	.cateList>.item>.logo {
		width: 60rpx;
		height: 60rpx;
	}

	.cateList>.item>.logo>image {
		width: 100%;
		height: 100%;
	}

	.cateList>.item>.name {
		font-size: 24rpx;
	}


	/* 精选列表 */
	.selectList {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}

	.selectList>.item {
		box-sizing: border-box;
		width: 350rpx;
		padding: 15rpx;
		border: 1rpx solid #eee;
		box-shadow: 3px 3px 3px #eee;
		/* 阴影 */
	}

	.selectList>.item>.pic {
		width: 313rpx;
		height: 320rpx;
		border: 1rpx solid #ccc;
	}

	.selectList>.item>.name {
		overflow: hidden;
		-webkit-line-clamp: 2;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		color: #666;
		font-size: 14px;
	}

	.selectList>.item>.pic>image {
		width: 100%;
		height: 100%;
	}

	.title {
		text-align: center;
		color: orange;
	}

	.selectList>.item>.msg {
		display: flex;
		justify-content: space-between;
	}
	.selectList>.item>.msg>.price{
		background: #ff6700;
		font-size: 12px;
		color: #fff;
		padding: 3px 5px;
		border-radius: 5px;
	}
	.selectList>.item>.msg>.tag{
		background: orange;
		font-size: 12px;
		color: #fff;
		padding: 3px 5px;
		border-radius: 5px;
	}
</style>